//
//  TTMineFormViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/8/29.
//  Copyright © 2019 admin. All rights reserved.
//

#import "TTMineFormViewCell.h"

@interface TTMineFormViewCell ()

@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *countLabel;  // 数字

@end

@implementation TTMineFormViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height - 20)];
        _imageView.contentMode = UIViewContentModeCenter;
//        _imageView.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_imageView];
        
        _titleLabel = [UILabel labelTextCenterWithTitle:@"" color:UIColorHex(666666) fontSize:11];
        _titleLabel.frame = CGRectMake(0, _imageView.bottom, self.width, 14);
        [self.contentView addSubview:_titleLabel];
        
        _countLabel = [UILabel labelTextCenterWithTitle:@"" color:UIColorHex(ffffff) fontSize:10];
        _countLabel.layer.cornerRadius = 7.5;
        _countLabel.layer.backgroundColor = [UIColor redColor].CGColor;
        _countLabel.frame = CGRectMake(self.width * 0.5, 3, 20, 15);
        [self.contentView addSubview:_countLabel];
        
    }
    return self;
}


- (void)setModel:(TTMineItemModel *)model
{
    _model = model;
    
    self.imageView.image = [UIImage imageNamed:model.imageName];
    self.titleLabel.text = model.title;
    
    
    if (model.count == 0) {
        self.countLabel.hidden = YES;
        self.countLabel.text = @"";
    } else {
        self.countLabel.hidden = NO;
        NSString *str = [NSString stringWithFormat:@"%d", model.count];
        CGFloat w = [str boundingRectWithSize:CGSizeMake(MAXFLOAT, 18) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12]} context:nil].size.width + 5;
        self.countLabel.text = str;
        w = w < 15 ? 15 : w;
        self.countLabel.width = w;   
    }
    
}


@end
